package com.nerve.android.cloudoffice.service.data;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.nerve.android.cloudoffice.common.Const;
import com.nerve.android.cloudoffice.common.Reply;
import com.nerve.android.cloudoffice.domain.Notify;
import com.nerve.android.cloudoffice.service.NetService;

/**
 * @project: Cloudoffice
 * @file: NotifyData.java
 * @package: com.nerve.android.cloudoffice.service.data
 * @description:
 *
 * @author: 集成显卡	1053214511@qq.com
				IBM GDC, zengxm@cn.ibm.com
 * @date&time: Aug 15, 2013
 * @change log:
 */
public final class NotifyData {

	private static final String URL = Const.HOST + "notify/";
	
	/**
	 * @method name: list
	 * @description:  list 会放在 reply中的message属性中，总数会放在 reply 的data属性中
	 * @return type: Reply
	 *
	 * @param page
	 * @return
	 */
	public static Reply list(int page){
		Reply re = NetService.get(URL + "list.htm?pageSize=40&page=" + page);
		if(!re.isError()){
			List<Notify> list = JSON.parseArray(re.getMessage().toString(), Notify.class);
			
			re.setMessage(list);
		}
		
		return re;
	}
	
	public static Reply add(Notify notify){
		Map<String, String> map = new HashMap<String, String>();
		map.put("notify.title", notify.getTitle());
		map.put("notify.message", notify.getMessage());
		
		Reply re = NetService.post(URL + "add.htm", map);
		
		return re;
	}
}